/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
         http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#pragma once

#include "Widget.h"

//EngineAPI_EXPORT void f_ui绘制模板_图标绘制(S_2D画布* s, S_图标绘制ID& id, uint16 属性ID, std::string 图标集);
//EngineAPI_EXPORT void f_ui绘制模板_画行文本(S_2D画布* s, S_行文本绘制ID& 文本ID, uint16 属性ID, const S_Font& 字体);
//EngineAPI_EXPORT bool f_ui绘制模板_重置凸矩形数量(S_2D画布* 画布, S_单色绘制ID& id, uint32 num);



struct S_矢量绘制数据 {
	std::vector<S_2DConvexRect>	区域;
	std::vector<S_GPU内存块*>	形状;
	std::vector<S_2D颜色包>		颜色;
	std::vector<vec2>			位置;

	std::vector<std::u16string> 字符文本;
	std::vector<S_Rect2Df>		字符区域;
	std::vector<S_RGBA8UI>		字符颜色;
	std::vector<E_对齐方式>		对齐方式;

	std::vector<std::u16string> 图标名称;
	std::vector<S_RGBA8UI>		图标颜色;
	std::vector<vec2>			图标位置;
	std::vector<vec2>			图标大小;

};



class EngineAPI_EXPORT ui_绘制模板_Vec {
	S_单色边面ID		m_背景ID;
	
	S_单色文本绘制ID	m_分量数值文本;
	S_单色文本绘制ID	m_分量名称文本;
	S_2D画布*			m_画布;

	//S_sf_文字GPU参数映射	m_Text数值Prt;
	//S_sf_文字GPU参数映射	m_Text名称Prt;
	
public:
	ui_绘制模板_Vec();

	float32				m_字号;

	void f_Layout(C_Widget* w);
	
};





class EngineAPI_EXPORT ui_绘制模板_行文本绘制 : public ui_绘制模板 {
	S_行文本绘制ID   m_文本;
	S_2D画布*        m_画布;
	const S_Font*    m_字体;
	uint32           m_单行字符最大数量;
public:
	ui_绘制模板_行文本绘制(uint16 单行字符最大数量 = 20);
	~ui_绘制模板_行文本绘制();
	
	float32				m_字号;
	uint16				m_画布属性;
	S_sf_文字GPU参数映射	m_Prt;

	void	f_Draw(S_2D画布* 画布, const S_Font* 字体, uint16 属性ID);
	void	f_alloc(uint32 变换num, uint32 所有字符num);
	void	f_设置文本(const S_Rect2Df& rect, const S_RGBA8UI& color, uint32 变换GPU偏移, std::wstring txt);
	void	f_居中绘制文本(const S_Rect2Df& rect, const S_RGBA8UI& color, uint32 变换GPU偏移, std::u16string txt);
	void	f_绘制文本(const S_Rect2Df& rect, const S_RGBA8UI& color, uint32 变换GPU偏移, std::wstring txt, E_对齐方式 方式, float32 缩放 = 1);
	void	f_绘制刻度数字(S_Rect2Df& rect, uint32 num, vec2 开始_步进, float32 间隔);
	void	f_Close(S_2D画布* 画布);
	void	f_Close(uint32 num = 0);

};





class EngineAPI_EXPORT ui_绘制模板_预设图形 : public ui_绘制模板 {
	
	S_2D画布*          m_画布;
	
public:
	ui_绘制模板_预设图形();
	~ui_绘制模板_预设图形();

	uint8		m_属性;
	S_凸边图元	m_图元;

	void	f_Draw(S_2D画布* 画布, const S_凸边图元& 链接参数, E_笔刷类型 笔刷, float32 线宽 = 1.0);
	
	void	f_alloc(uint32 num);
	
	void	f_setColor(uint32 id, const S_RGBA8UI& C);
	void	f_绘制滚动条(uint32 gpuOffset, C_Widget* 滚动条);
	uint32	f_fill顶点(vec2* 顶点, uint32 num);
	void	f_set单色填充(uint32 id, const mat3X2& mat, const S_RGBA8UI& C, const uvec2& 图元ID, float32 线宽 = 1.0);
	void	f_set单色线(uint32 id, const mat3X2& mat, const S_LineProp& C, const uvec2& 图元ID, float32 线宽 = 1.0);
	void	f_set色轮(uint32 id, const mat3X2& mat, const uvec2& 图元ID, const S_ColorTake& ct);
	
	void	f_Close(uint32 num = 0);

};

class EngineAPI_EXPORT ui_绘制模板_图标 : public ui_绘制模板 {
	S_图标绘制ID m_ID;
	
	S_2D画布* m_画布;
	S_sf_图标GPU映射	m_Prt;

public:
	ui_绘制模板_图标();
	~ui_绘制模板_图标();

	void	f_Draw单色(S_2D画布* 画布, uint16 属性ID, std::string ico集);
	void	f_Draw彩色(S_2D画布* 画布, uint16 属性ID, std::string ico集);
	void	f_alloc(uint32 num);
	void	f_set(std::string ico, uint32 offset, const mat3X2 mat, const S_RGBA8UI 颜色);
	void	f_Close();
};

class EngineAPI_EXPORT ui_绘制模板_刻度线 {
	S_图标绘制ID m_ID;
	S_GPU内存块 id_变换;
	S_GPU内存块 id_颜色;

	mat3X2* m_Mat;
	uint32* m_线Color;
	uint32* m_文字Color;
	
	S_2D画布* m_画布;

	
public:
	ui_绘制模板_刻度线();
	~ui_绘制模板_刻度线();

	vec2	m_间隔比例;

	void	f_Draw(S_2D画布* 画布, uint16 属性ID);
	void	f_Draw网格(S_2D画布* 画布, uint16 属性ID);
	void	f_alloc(uint32 num);
	void	f_set(uint32 线num, const mat3X2 mat, S_RGBA8UI 颜色, uint32 offset = 0);
	void	f_set(uint32 offset, uint32 线num, const mat3X2 mat, S_RGBA8UI 颜色);
	
};

class ui_绘制模板_曲线 {
	S_单色绘制ID			m_背景;

	S_板载缓存* m_曲线ID;
	uint32		m_点元素;
	uint32		m_线元素;

	S_CurvePoint2*	m_曲线点Ptr;
	uint32*			m_曲线IDPtr;

	std::vector<std::vector<uvec2>> m_线点ID;

	S_2D画布*	m_画布;
	suvec2		m_Dim;
	
public:
	ui_绘制模板_曲线();

	uint8		m_属性;
	S_板载缓存* m_曲线点;
	uint32		m_点数量;

	void f_Draw控制点(S_2D画布* 画布, uint16 属性ID);
	void f_Draw(S_2D画布* 画布, uint16 属性ID, bool 多曲线 = false);

	void f_begin(uint32 线段区数量);
	void f_end();

	void f_setPoint(uint32 offset, const S_CurvePoint2& 曲线点);
	void f_setPointColor(uint32 offset, const uint32 color);
	void f_setPointColor(uint32 offset, const S_RGBA8UI& color);
	void f_setPointSelect(uint32 offset, uint32 b);
	void f_setPointType(uint32 offset, uint32 b);
	void f_setLine(uint32 offset, uint16 left_id, uint16 rigth_id);

	void f_插入点(const S_CurvePoint2& 曲线点, const S_RGBA8UI& color, uint32 链接ID, uint64 offset);

	void f_map();
	void f_unmap();
};

class ui_绘制模板_自定义线 {
	S_图标绘制ID     m_ID;
	S_2D画布*        m_画布;
	
	S_sf_单色GPU映射 m_Prt;
	
public:
	ui_绘制模板_自定义线();
	~ui_绘制模板_自定义线();

	uint32	m_NextID;
	std::vector<vec2> lines;

	void	f_Draw(S_2D画布* 画布, uint16 属性ID, E_笔刷类型 笔刷 = E_笔刷类型::e_单色填充);
	void	f_alloc(uint32 num, const S_RGBA8UI& C = { 0,0,0,255 });
	void	f_End();


	void	f_set下一个顶点(const vec2& pos, const S_RGBA8UI& C);
	void	f_set顶点(uint32 id, const vec2& pos);
	void	f_set顶点(uint32 id, const vec2& pos, const S_RGBA8UI& C);
	void	f_Close(uint32 num = 0);
	
	void	f_get线坐标();
};


class ui_绘制模板_纹理 {
	S_2D画布* m_画布;

	S_GPU内存块 m_纹理变换;
	S_GPU内存块 m_纹理属性;
	S_GPU内存块 m_纹理ID;
	uint32          m_层ID;

	S_MulTex_ConstPush m_ConstPush;
public:
	ui_绘制模板_纹理();
	~ui_绘制模板_纹理();

	uint32	m_层;

	void f_Draw(S_2D画布* 画布, uint16 属性ID, E_笔刷类型 笔刷 = E_笔刷类型::e_纹理, S_纹理* 纹理 = nullptr);
	void f_Draw(S_2D画布* 画布, uint16 属性ID, S_纹理集* 纹理集);
	void f_alloc(uint32 num);
	uint32 f_set(uint32 id, const mat3X2& mat, const uvec2& 图元ID, const S_RGBA8UI& C, const S_TextueProp& texProp = {});
	uint32 f_set(uint32 id, const mat3X2& mat, const uvec2& 图元ID, uint32 texID);
	void f_绑定纹理(S_纹理* text, uint32 id, const S_RGBA8UI& C = {});
	void f_Close(uint32 num = 0);
};



class ui_绘制模板_线段 {
	S_2D画布* m_画布;

	uint32	    m_层ID;
	uint8		m_属性;
	S_凸边图元	m_图元;
	

	S_GPU内存块  m_线段数据;

public:
	ui_绘制模板_线段();
	~ui_绘制模板_线段();

	void	f_Draw(S_2D画布* 画布, uint16 属性ID, E_笔刷类型 笔刷 = E_笔刷类型::e_圆公切链接线);
	void	f_alloc(uint32 num);
	
	void	f_set(uint32 id, const S_CurvePoint2& point);
	void	f_Close(uint32 num = 0);

};



//auto ui_dt_行编辑框 = [](C_Widget& box){
//	
//};

void f_ui_draw_temple_树形框(C_Widget* self, S_2DConvexRect& 区域, S_2D颜色包& 颜色);

int32 f_ui_drawTemple_刻度缩放(float32& 刻度跨度, float32 缩放, float32 初始跨度);

void f_ui_draw_temple_拖放条手柄(
	C_Widget* self, 
	std::vector<S_2DConvexRect>&	区域,
	std::vector<S_GPU内存块*>&		形状,
	std::vector<S_2D颜色包>&		颜色,
	std::vector<vec2>&				位置,
	bool							扩展
);

void f_ui_drawTemple_PropsName (
	S_矢量绘制数据&	绘制数据,

	S_Props&		prop,
	vec2			pos,
	vec2			size
);

void f_ui_drawTemple_PropsOps(
	S_矢量绘制数据&	绘制数据,

	C_Widget*		widget,
	S_Props&		prop,
	S_2DConvexRect& rect,
	vec2			pos
);

void f_ui_drawTemple_PropsLineStr(
	S_矢量绘制数据&	绘制数据,

	C_Widget*		widget,
	S_Props&		prop,
	S_2DConvexRect& rect,
	vec2			pos
);


void f_ui_drawTemple_PropsValue(
	S_矢量绘制数据&	绘制数据,

	C_Widget*		widget,
	S_Props&		prop,
	S_2DConvexRect& rect,
	vec2			pos
);

void f_ui_drawTemple_PropsVec(
	S_矢量绘制数据&	绘制数据,

	C_Widget*		widget,
	S_Props&		prop,
	S_2DConvexRect& rect,
	vec2			pos
);

void f_ui_drawTemple_PropsUI32Flage(
	S_矢量绘制数据&	绘制数据,

	C_Widget*		widget,
	S_Props&		prop,
	S_2DConvexRect& rect,
	vec2			pos
);

void f_ui_drawTemple_PropsEnum(
	S_矢量绘制数据&	绘制数据,

	C_Widget*		widget,
	S_Props&		prop,
	S_2DConvexRect& rect,
	vec2			pos
);

void f_ui_drawTemple_Strings(
	S_矢量绘制数据&	绘制数据,

	vec2			pos,
	vec2			size,
	S_RGBA8UI		color,
	bool			自动换行
);

void f_ui_drawTemple_ColorDisc(
	S_矢量绘制数据&	绘制数据,

	C_Widget*		widget,
	vec2			pos,
	vec2			size
);

void f_ui_drawTemple_PropsObjectContainer(
	S_矢量绘制数据&	绘制数据,

	C_Widget*		widget,
	const S_Props&	prop
);



template<S_Surface2D* 背景>
auto constexpr f_ui_draw_temple_按钮 = [](vec2 pos) {
	


};

#define DEF_ui_draw_temple_按钮(背景, pos)          \
	f_vg_tranform((*背景), (pos));                  \
	f_vg_drawConvex((*背景), 4, 形状, 区域);        \












//class ui_绘制模板_表格 {
//	S_2D画布* m_画布;
//
//	S_GPU内存块  m_表格线;
//	S_GPU内存块  m_颜色;
//public:
//	ui_绘制模板_表格();
//	~ui_绘制模板_表格();
//
//	//S_渐变图元	m_图元;
//	uint32	m_层;
//	vec2    m_大小;
//
//	void	f_Draw(S_2D画布* 画布, uint16 属性ID);
//	void	f_fill(uint32 hNum, uint32 vNum);
//	
//	void	f_Close(uint32 num = 0);
//};



//class EngineAPI_EXPORT ui_绘制模板_块文本绘制 : public ui_绘制模板 {
//	S_单色文本绘制ID		m_文本;
//	S_单色文本绘制ID		m_行号;
//	S_sf_文字GPU参数映射	m_映射指针;
//	S_sf_文字GPU参数映射	m_行号映射指针;
//
//	S_单色绘制ID			m_光标ID;
//	S_单色绘制ID			m_选取ID;
//
//	S_2D画布*				m_画布;
//
//public:
//	ui_绘制模板_块文本绘制();
//
//	float32				m_字号;
//	uint16				m_单行字符最大数量;
//
//	S_sf_文字GPU参数映射	f_GPU参数修改_begin(S_2D画布* 画布, uint32 num, uint32 行);
//	void					f_填充文本(S_2D画布* 画布, std::wstring txt, const S_RGBA8UI& color, vec2 pos, uint32 offset);
//	void					f_填充文本(S_2D画布* 画布, const S_文档文本& txt, vec2 pos, const S_Font& 字体, int16 行距);
//	void					f_GPU参数修改_end(S_2D画布* 画布);
//
//	void f_开启编辑(S_2D画布* 画布, C_Widget* w);
//	void f_输入(S_2D画布* 画布, C_文本框* box, std::wstring& text);
//	void f_输入完成(S_2D画布* 画布, C_文本框* box);
//
//	void f_框选(S_2D画布* 画布, C_文本框* box);
//
//};
